//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.andromeda.androbench2;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;
import android.content.SharedPreferences.Editor;
import android.graphics.Point;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;

public class Startupbench extends CustomActivity {
    private static final int KBYTE = 1024;
    private static final int MBYTE = 1048576;
    Builder dlg_bld_proc_bench;
    boolean flag_microbench;
    boolean flag_sqlitebench;
    Context mContext;
    SharedPreferences sp_Data;
    SharedPreferences sp_Flag;
    Editor sp_e_Flag;

    public Startupbench() {
    }

    private void askProcess() {
        int var1 = this.sp_Data.getInt("TargetDevice", 0);
        int var2 = this.sp_Data.getInt("Num_Thread", 0) * 1024 * this.sp_Data.getInt("OneFileSize", 0);
        int var3 = 10 * 1024 * this.sp_Data.getInt("Num_Sqlite", 0) * this.sp_Data.getInt("DatabaseSize", 0);
        System.out.println("test_total_file_size: " + var2);
        System.out.println("test_sqlite_space: " + var3);
        this.dlg_bld_proc_bench = new Builder(this);
        this.dlg_bld_proc_bench.setCancelable(false).setPositiveButton("Yes", new OnClickListener() {
            public void onClick(DialogInterface var1, int var2) {
                Startupbench.this.sp_e_Flag.remove("StartingBench");
                Startupbench.this.sp_e_Flag.putBoolean("StartingBench", true);
                Startupbench.this.sp_e_Flag.commit();
                Intent var6 = new Intent();
                var6.setAction("com.androbench.CHANGE_TAB");
                var6.putExtra("CHANGE_TARGET", 1);
                var6.putExtra("MICRO", Startupbench.this.flag_microbench);
                var6.putExtra("SQLITE", Startupbench.this.flag_sqlitebench);
                Startupbench.this.sendBroadcast(var6);
            }
        }).setNegativeButton("No", new OnClickListener() {
            public void onClick(DialogInterface var1, int var2) {
                Startupbench.this.sp_e_Flag.remove("StartingBench");
                Startupbench.this.sp_e_Flag.putBoolean("StartingBench", false);
                Startupbench.this.sp_e_Flag.commit();
            }
        });
        String var5;
        if (this.flag_microbench && this.flag_sqlitebench) {
            var5 = "Are you sure you want to run all benchmarks? (recommended)";
        } else if (this.flag_microbench && !this.flag_sqlitebench) {
            var5 = "Are you sure you want to run micro-benchmark?";
        } else if (!this.flag_microbench && this.flag_sqlitebench) {
            var5 = "Are you sure you want to run SQLite benchmark?";
        } else {
            var5 = "?";
        }

        this.dlg_bld_proc_bench.setTitle("Benchmarking");
        this.dlg_bld_proc_bench.setIcon(R.drawable.dlgicon_accept);
        boolean var8 = this.flag_sqlitebench;
        byte var9 = 0;
        if (var8) {
            if (var1 == 0) {
                if (MemoryStatus.getAvailableInternalMemorySize() < 0L) {
                    var5 = "Your '/data' partition is not available!\n\nWould you like to reset the configuration?";
                    this.dlg_bld_proc_bench.setIcon(R.drawable.dlgicon_cancel);
                    var9 = 1;
                } else {
                    long var26;
                    int var25 = (var26 = (long)var3 - MemoryStatus.getAvailableInternalMemorySize()) == 0L ? 0 : (var26 < 0L ? -1 : 1);
                    var9 = 0;
                    if (var25 > 0) {
                        var5 = "Your '/data' partition has not enough free space!\n(Free space = " + MemoryStatus.getAvailableInternalMemorySize() / 1048576L + "MB)\n\nWould you like to reset the configuration?";
                        this.dlg_bld_proc_bench.setIcon(R.drawable.dlgicon_cancel);
                        var9 = 1;
                    }
                }
            } else if (MemoryStatus.getAvailableSDExternalMemorySize(this.mContext) < 0L) {
                var5 = "Your '" + MemoryStatus.getSDExternalPath(this.mContext) + "' partition is not available!\n\nWould you like to reset the configuration?";
                this.dlg_bld_proc_bench.setIcon(R.drawable.dlgicon_cancel);
                var9 = 1;
            } else {
                long var27;
                int var22 = (var27 = (long)var3 - MemoryStatus.getAvailableSDExternalMemorySize(this.mContext)) == 0L ? 0 : (var27 < 0L ? -1 : 1);
                var9 = 0;
                if (var22 > 0) {
                    var5 = "Your '" + MemoryStatus.getSDExternalPath(this.mContext) + "' partition has not enough free space!\n(Free space = " + MemoryStatus.getAvailableSDExternalMemorySize(this.mContext) / 1048576L + "MB)\n\nWould you like to reset the configuration?";
                    this.dlg_bld_proc_bench.setIcon(R.drawable.dlgicon_cancel);
                    var9 = 1;
                }
            }
        }

        if (this.flag_microbench) {
            if (var1 == 0) {
                if (MemoryStatus.getAvailableInternalMemorySize() < 0L) {
                    var5 = "Your '/data' partition is not available!\n\nWould you like to reset the configuration?";
                    this.dlg_bld_proc_bench.setIcon(R.drawable.dlgicon_cancel);
                    var9 = 1;
                } else if ((long)var2 > MemoryStatus.getAvailableInternalMemorySize()) {
                    var5 = "Your '/data' partition has not enough free space!\n(Free space = " + MemoryStatus.getAvailableInternalMemorySize() / 1048576L + "MB)\n\nWould you like to reset the configuration?";
                    this.dlg_bld_proc_bench.setIcon(R.drawable.dlgicon_cancel);
                    var9 = 1;
                }
            } else if (MemoryStatus.getAvailableSDExternalMemorySize(this.mContext) < 0L) {
                var5 = "Your '" + MemoryStatus.getSDExternalPath(this.mContext) + "' partition is not available!\n\nWould you like to reset the configuration?";
                this.dlg_bld_proc_bench.setIcon(R.drawable.dlgicon_cancel);
                var9 = 1;
            } else if ((long)var2 > MemoryStatus.getAvailableSDExternalMemorySize(this.mContext)) {
                var5 = "Your '" + MemoryStatus.getSDExternalPath(this.mContext) + "' partition has not enough free space!\n(Free space = " + MemoryStatus.getAvailableSDExternalMemorySize(this.mContext) / 1048576L + "MB)\n\nWould you like to reset the configuration?";
                this.dlg_bld_proc_bench.setIcon(R.drawable.dlgicon_cancel);
                var9 = 1;
            }

            String var16;
            if (var1 == 0) {
                var16 = MemoryStatus.getInternalFilesystem();
            } else {
                var16 = MemoryStatus.getSDExternalFilesystem(this.mContext);
            }

            boolean var17;
            if (!var16.equals("yaffs") && !var16.equals("yaffs2") && !var16.equals("ext2")) {
                var17 = true;
            } else {
                var17 = false;
            }

            if (!var17 && var9 == 0) {
                var5 = "To run microbenchmarks\nthe file system should support Direct I/O";
                this.dlg_bld_proc_bench.setIcon(R.drawable.dlgicon_warning);
            }
        }

        if (var9 != 2) {
            this.dlg_bld_proc_bench.setMessage(var5);
            AlertDialog var14 = this.dlg_bld_proc_bench.create();
            var14.show();
            CustomActivity.setSelector((ViewGroup)var14.getWindow().getDecorView());
            CustomActivity.setGlobalFont((ViewGroup)var14.getWindow().getDecorView());
        } else {
            this.sp_e_Flag.remove("StartingBench");
            this.sp_e_Flag.putBoolean("StartingBench", false);
            this.sp_e_Flag.commit();
        }
    }

    public void onCreate(Bundle var1) {
        super.onCreate(var1);
        this.setRequestedOrientation(1);
        this.setContentView(R.layout.startupbench);
        this.mContext = this.getApplicationContext();
        this.sp_Flag = this.getSharedPreferences("Flags", 0);
        this.sp_e_Flag = this.sp_Flag.edit();
        this.sp_Data = this.getSharedPreferences("Settings", 0);
        Point var2 = new Point(this.sp_Data.getInt("WindowWidth", 0), this.sp_Data.getInt("WindowHeight", 0));
        ImageView var3 = (ImageView)this.findViewById(R.id.iv_title);
        ImageView var4 = (ImageView)this.findViewById(R.id.btnStartingBenchmarking);
        ImageView var5 = (ImageView)this.findViewById(R.id.btnStartingMicroBenchmarking);
        ImageView var6 = (ImageView)this.findViewById(R.id.btnStartingSqliteBenchmarking);
        ImageView var7 = (ImageView)this.findViewById(R.id.iv_mark_csl);
        ImageView var8 = (ImageView)this.findViewById(R.id.iv_title_message);
        double var9 = (double)var2.x / (double)var3.getLayoutParams().width;
        var3.getLayoutParams().width = var2.x;
        var3.getLayoutParams().height = (int)(var9 * (double)var3.getLayoutParams().height);
        var2.y -= var3.getLayoutParams().height;
        System.out.println("Window size: " + var2.x + ", " + var2.y);
        if (var2.x > var2.y) {
            var2.x = -50 + var2.y;
        }

        double var11 = 0.8D * (double)var2.x / (double)var8.getLayoutParams().width;
        var8.getLayoutParams().width = (int)(0.8D * (double)var2.x);
        var8.getLayoutParams().height = (int)(var11 * (double)var8.getLayoutParams().height);
        double var13 = 0.9D * (double)var2.x / (double)var4.getLayoutParams().width;
        var4.getLayoutParams().width = (int)(0.9D * (double)var2.x);
        var4.getLayoutParams().height = (int)(var13 * (double)var4.getLayoutParams().height);
        double var15 = 0.9D * (double)var2.x / (double)var5.getLayoutParams().width;
        var5.getLayoutParams().width = (int)(0.9D * (double)var2.x);
        var5.getLayoutParams().height = (int)(var15 * (double)var5.getLayoutParams().height);
        double var17 = 0.9D * (double)var2.x / (double)var6.getLayoutParams().width;
        var6.getLayoutParams().width = (int)(0.9D * (double)var2.x);
        var6.getLayoutParams().height = (int)(var17 * (double)var6.getLayoutParams().height);
        double var19 = 0.07D * (double)var2.y / (double)var7.getLayoutParams().height;
        var7.getLayoutParams().width = (int)(var19 * (double)var7.getLayoutParams().width);
        var7.getLayoutParams().height = (int)(0.07D * (double)var2.y);
        ((ImageButton)this.findViewById(R.id.btnStartingBenchmarking)).setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View var1) {
                Startupbench.this.flag_microbench = true;
                Startupbench.this.flag_sqlitebench = true;
                Startupbench.this.askProcess();
            }
        });
        ((ImageButton)this.findViewById(R.id.btnStartingMicroBenchmarking)).setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View var1) {
                Startupbench.this.flag_microbench = true;
                Startupbench.this.flag_sqlitebench = false;
                Startupbench.this.askProcess();
            }
        });
        ((ImageButton)this.findViewById(R.id.btnStartingSqliteBenchmarking)).setOnClickListener(new android.view.View.OnClickListener() {
            public void onClick(View var1) {
                Startupbench.this.flag_microbench = false;
                Startupbench.this.flag_sqlitebench = true;
                Startupbench.this.askProcess();
            }
        });
    }
}
